package com.cch.examSystem.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class InitTestpage extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request,response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=utf-8");
		PrintWriter out = response.getWriter();
		String scale_id=request.getParameter("scale_id");
				/**
				 * 查询试卷的信息（注意随机问卷）
				 * 问卷(对象)信息：
				 * scale_id、category_id;manager_id;name;
				 * introduction;guide;import_time;alter_time;
				 * type;test_ime;total_score;form;question_info;strategy;
				 * 问题(对象)信息：
				 * question_id;category_id;manager_id;question;
				 * options;reference_score;question_answer;
				 * difficulity_reank;question_type;alter_time
				 * 
				 * 我需要的信息（及格式）：
				 * 问卷信息json：scale_info:{"scale_id":12,"type":"知识点测试","name":"xxx考试","test_time":"02:30:00"}
				 * 问题json：questions：[{\"question_id\":\"1231\",\"question_type\":\"单选题\",\"question\":\"Questions 16 to 18 are based on the passage you have just heard.\",\"options\":{\"A\":\"They shared mutual friends in school.\",\"B\":\"They had many interests in common.\"},\"reference_score\":\"12\"},{\"question_id\":\"1231\",\"question_type\":\"多选题\",\"question\":\"sdfawefasfwef?\",\"options\":{\"A\":\"safas\",\"B\":\"They had many interests in common.\"},\"reference_score\":\"12\"}]
				 * 答案json：{"1231":["A"],"question_id":["B"],...}
				 */
				String model="{\"scale_id\":%d,\"type\":\"%s\",\"name\":\"%s\",\"test_time\":\"%s\"}";
				String questions="[{\"question_id\":\"1231\",\"question_type\":\"单选题\",\"question\":\"Questions 16 to 18 are based on the passage you have just heard.\",\"options\":{\"A\":\"They shared mutual friends in school.\",\"B\":\"They had many interests in common.\"},\"reference_score\":\"12\"},{\"question_id\":\"1234\",\"question_type\":\"多选题\",\"question\":\"sdfawefasfwef?\",\"options\":{\"A\":\"safas\",\"B\":\"They had many interests in common.\"},\"reference_score\":\"12\"}]";
				String scale_info = String.format(model,12,"知识点测试", "xxx考试","00:00:30");
				String returnInfo=String.format("{\"scale_info\":%s,\"questions\":%s}", scale_info,questions);
				out.print(returnInfo);
				String answer="{\"1231\":[\"A\"],\"1234\":[\"B\",\"A\"]}";
				HttpSession session=request.getSession();
				session.setAttribute("answer", answer);
		out.flush();
		out.close();
	}

}
